//-------------------------------------------------------------------
//	Copyright (c) 2010-2012 Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_BASE_RESOURCE_H
#define _UX_BASE_RESOURCE_H

#include <Includes.h>
#include "../Systems/FileSys/IFile.h"
#include "../Systems/Config/CConfig.h"

namespace Engine
{
namespace Resources
{

	//
	// Config Resource Interface
	//

	/*class IConfigResource
	{
	public:
		virtual bool AddConfigNode(static_obj_node_t pBaseNode) = 0;		// to parsing file
		virtual bool AddConfigSaveNode(static_obj_node_t pBaseNode) = 0;	// to save in config file
	};*/



#if UX_RESOURCE_MANAGEMENT_TYPE == __RESOURCE_WITH_FILENAME


	//
	// Resource with file address
	//

	class _EXPORT_ CResource : protected CReferenced, public CEngBaseObject
	{
		friend class Engine::CoreSystems::CResourceManager;

	private:
		TFileAddress  *	_pFileAddress;

		void operator = (const CResource &) {}
		virtual void _Release();
		
	protected:
		usize			_uRAMSize,			// resource data size in RAM
						_uVRAMSize;			// resource data size in VRAM

	protected:
		CResource();
		CResource(const char *pFileName);
		virtual ~CResource();

		virtual bool _Replace(CResource *pRes) = 0;
		virtual bool _Load(IFilePtr pFile, uint uSize) = 0;
		virtual bool _Save(IFilePtr pFile) = 0;
		virtual bool _Reload(IFilePtr pFile, bool bRecursive) = 0;

		static  void _s_AddRef(CResource *pRes);

	public:
		bool Load();
		bool Load(IFilePtr pFile, uint uSize = 0);

		bool Save(const char *pFileName);
		bool Save(IFilePtr pFile);

		bool Reload(bool bRecursive = true);

		virtual bool Compare(CResource *pRes);

		virtual void Destroy()								{ return; }
		virtual bool IsValid()		const					{ return false; }

		virtual e_resource::type	GetType()		 const	{ return e_resource::UNKNOWN; }
		virtual e_res_delete::type	GetDeleteFlags() const	{ return e_res_delete::NO_REF; }	// for ResMan
		
		TFileAddress *				GetFileAddress() const	{ return _pFileAddress; }
		usize						GetRAMSize()	 const	{ return _uRAMSize; }
		usize						GetVRAMSize()	 const	{ return _uVRAMSize; }

		bool ClearFileInfo();


		// CEngBaseObject //
		virtual void  Release();
	};


#elif UX_RESOURCE_MANAGEMENT_TYPE == __RESOURCE_WITH_ID


	//
	// Resource with id
	//
	
	class _EXPORT_ CResource : protected CReferenced, public CEngBaseObject
	{
		friend class Engine::CoreSystems::CResourceManager;

	private:
		uint			_uResFileID;

		void operator = (const CResource &) {}
		virtual void _Release();
		
	protected:
		usize			_uRAMSize,			// resource data size in RAM
						_uVRAMSize;			// resource data size in VRAM

	protected:
		CResource();
		CResource(const char *pFileName);
		virtual ~CResource();
		virtual bool _Replace(CResource *pRes) = 0;

		static void _s_AddRef(CResource *pRes);

	public:
		bool Load();
		bool Save(const char *pFileName);

		virtual bool Compare(CResource *pRes);
		
		virtual bool LoadF(IFilePtr pFile, uint uSize = 0) = 0;
		virtual bool SaveF(IFilePtr pFile) = 0;

		virtual bool Destroy()								{ return SR_FALSE; }
		virtual bool IsValid()		const					{ return false; }

		virtual e_resource::type		GetType()		 const	{ return e_resource::UNKNOWN; }
		virtual e_res_delete::type	GetDeleteFlags() const	{ return e_res_delete::NO_REF; }		// for ResMan
		TFileAddress *				GetFileAddress() const	{ return nullptr; }

		bool ClearFileInfo();


		// CEngBaseObject //
		virtual void  Release();
	};

#endif	// UX_RESOURCE_MANAGEMENT_TYPE

//-------------------------------------------------------------------

}	// EngineResource
}	// Engine

#endif	// _UX_BASE_RESOURCE_H